"""
各种匹配算法的基类
"""

import numpy as np
import time


class Matching:
    """
    各种匹配算法的基类
    """

    def __init__(self, catalog_path, **kwargs):
        """
        Arguments:
            K (np.ndarray) : the intrinsic matrix of the camera
            catalog_path (np.ndarray) : the path to catalog of the database, structured as :
                1-1: ndarray, shape (N, M) N descriptors in cluster 1 with cluster 1
                1-2: ndarray, shape (N, M) N descriptors in cluster 1 with cluster 2
                ...
        """
        catalog = np.load(catalog_path, allow_pickle=True)
        self.catalog = catalog["catalog"]
        self.descriptor = catalog["descriptor"]
        self.idx = catalog["idx"]
        self.constants = catalog["constants"].item()

    def __call__(self, input_, *args, **kwargs):
        t = time.time()
        result = self.identify(input_, *args, **kwargs)
        return time.time() - t, result

    def identify(self, input_, *args, **kwargs):
        raise NotImplementedError
